package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.FixedAssetsEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 固定资产表Provider
 *
 * @author generator
 * @date 2020-03-12 17:08
 */
public class FixedAssetsProvider {

    /**
     * 增加FixedAssets
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String insertFixedAssets(@Param("entity") FixedAssetsEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" fixed_assets ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" assets_no ", " #{entity.assetsNo,jdbcType=VARCHAR} ");
                VALUES(" assets_name ", " #{entity.assetsName,jdbcType=VARCHAR} ");
                VALUES(" specification_no ", " #{entity.specificationNo,jdbcType=VARCHAR} ");
                VALUES(" assets_unit ", " #{entity.assetsUnit,jdbcType=VARCHAR} ");
                VALUES(" manufacturer ", " #{entity.manufacturer,jdbcType=VARCHAR} ");
                VALUES(" use_department ", " #{entity.useDepartment,jdbcType=VARCHAR} ");
                VALUES(" assets_source ", " #{entity.assetsSource,jdbcType=VARCHAR} ");
                VALUES(" depreciation_degree ", " #{entity.depreciationDegree,jdbcType=VARCHAR} ");

                if (entity.getDepreciationYear() != null) {
                    VALUES(" depreciation_year ", " #{entity.depreciationYear,jdbcType=TINYINT} ");
                }

                VALUES(" original_value ", " #{entity.originalValue,jdbcType=DECIMAL} ");
                VALUES(" enable_date ", " #{entity.enableDate,jdbcType=DATE} ");
                VALUES(" use_state ", " #{entity.useState,jdbcType=VARCHAR} ");
                VALUES(" scrap_date ", " #{entity.scrapDate,jdbcType=DATE} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改FixedAssets
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String updateFixedAssets(@Param("entity") FixedAssetsEntity entity) {
        return new SQL() {
            {
                UPDATE(" fixed_assets ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" assets_no = #{entity.assetsNo,jdbcType=VARCHAR} ");
                SET(" assets_name = #{entity.assetsName,jdbcType=VARCHAR} ");
                SET(" specification_no = #{entity.specificationNo,jdbcType=VARCHAR} ");
                SET(" assets_unit = #{entity.assetsUnit,jdbcType=VARCHAR} ");
                SET(" manufacturer = #{entity.manufacturer,jdbcType=VARCHAR} ");
                SET(" use_department = #{entity.useDepartment,jdbcType=VARCHAR} ");
                SET(" assets_source = #{entity.assetsSource,jdbcType=VARCHAR} ");
                SET(" depreciation_degree = #{entity.depreciationDegree,jdbcType=VARCHAR} ");

                if (entity.getDepreciationYear() != null) {
                    SET(" depreciation_year = #{entity.depreciationYear,jdbcType=TINYINT} ");
                }

                SET(" original_value = #{entity.originalValue,jdbcType=DECIMAL} ");
                SET(" enable_date = #{entity.enableDate,jdbcType=DATE} ");
                SET(" use_state = #{entity.useState,jdbcType=VARCHAR} ");
                SET(" scrap_date = #{entity.scrapDate,jdbcType=DATE} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询FixedAssets列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String listFixedAssets(@Param("entity") FixedAssetsEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,assets_no,assets_name,specification_no,assets_unit,manufacturer,use_department,assets_source,depreciation_degree,depreciation_year,original_value,enable_date,use_state,scrap_date,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" fixed_assets ");

                if (entity.getAssetsNo() != null) {
                    WHERE(" assets_no = #{entity.assetsNo,jdbcType=VARCHAR} ");
                }

                if (entity.getAssetsName() != null) {
                    WHERE(" assets_name = #{entity.assetsName,jdbcType=VARCHAR} ");
                }

                if (entity.getSpecificationNo() != null) {
                    WHERE(" specification_no = #{entity.specificationNo,jdbcType=VARCHAR} ");
                }

                if (entity.getAssetsUnit() != null) {
                    WHERE(" assets_unit = #{entity.assetsUnit,jdbcType=VARCHAR} ");
                }

                if (entity.getManufacturer() != null) {
                    WHERE(" manufacturer = #{entity.manufacturer,jdbcType=VARCHAR} ");
                }

                if (entity.getUseDepartment() != null) {
                    WHERE(" use_department = #{entity.useDepartment,jdbcType=VARCHAR} ");
                }

                if (entity.getAssetsSource() != null) {
                    WHERE(" assets_source = #{entity.assetsSource,jdbcType=VARCHAR} ");
                }

                if (entity.getDepreciationDegree() != null) {
                    WHERE(" depreciation_degree = #{entity.depreciationDegree,jdbcType=VARCHAR} ");
                }

                if (entity.getDepreciationYear() != null) {
                    WHERE(" depreciation_year = #{entity.depreciationYear,jdbcType=TINYINT} ");
                }

                if (entity.getOriginalValue() != null) {
                    WHERE(" original_value = #{entity.originalValue,jdbcType=DECIMAL} ");
                }

                if (entity.getEnableDate() != null) {
                    WHERE(" enable_date = #{entity.enableDate,jdbcType=DATE} ");
                }

                if (entity.getUseState() != null) {
                    WHERE(" use_state = #{entity.useState,jdbcType=VARCHAR} ");
                }

                if (entity.getScrapDate() != null) {
                    WHERE(" scrap_date = #{entity.scrapDate,jdbcType=DATE} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}